<#assign module="marketing"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/gird.css">
</@override>
<@override name="body">
<div class="row">
 		<div class="col-xs-7">
	         <form class="form-inline" id="SearchForm" method="get">
		  	   <div class="form-group">
		       <input class="form-control" id="couponCode" name="couponCode" placeholder="输入优惠券编码" type="text" value="">
		       </div>
		       <div class="form-group">
		       <input class="form-control" id="phone" name="phone" placeholder="输入客户电话" type="text" value="">
		       </div>
		       <div class="form-group">
		       <input type="submit" class="btn btn-default" value="查询">
		       </div>
		       <div class="form-group">
		       <input type="button" id="clear_time" class="btn btn-default" value="全部">
		       </div>
	        </form>
		</div>
		<div class="col-xs-5">
			<button class="pull-right button button-rounded button-flat-blue" onclick="window.location='${ctx}/couponrule/mass/${couponRule.id}';"><i class="icon-plus"></i>&nbsp;生成优惠劵</button>
	 		<button class="pull-right button button-rounded button-flat-blue" onclick="window.location='${ctx}/couponrule/export/${couponRule.id}';"><i class="glyphicon glyphicon-save"></i>&nbsp;导出优惠劵</button>
		</div>	
</div>
<div class="row margin-top">
	<div class="col-xs-12">
	<div class="table-responsive">
	
	<div class="panel panel-default">
		<div class="panel-heading">
		
			${couponRule.title}&nbsp;&nbsp;有效期：${couponRule.start?string('yyyy/MM/dd HH:mm')}&nbsp;-&nbsp;${couponRule.end?string('yyyy/MM/dd HH:mm')}
			&nbsp;&nbsp;
			<#if couponRule.timeStatus==0>
				（未开始）
			<#elseif couponRule.timeStatus==1>
				（使用中）
			<#elseif couponRule.timeStatus==2>
				（已过期）
			</#if>
	    </div>
    </div>
    
	<div class="panel panel-default margin-top">
		
		<table class="table table-hover table-striped">
			<thead>
			<tr style="font-size:14px;">
				<th>编码</th>
				<th>密码</th>
				<th>使用状态</th>
				<th>客户称呼/手机号</th>
				<th>客户类型</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				<#if (page.content)?? >
			  	<#list page.content as data>
					<tr>
						<td>
							${data.code?if_exists}
						</td>
						<td id="codeKey_${data.id}">
							<#if data.codeKey??>
								**************							
							<#else>
								-
							</#if>
						</td>
						<td class="status-td">
							<#if data.status==0>
								未绑定
							<#elseif data.status==1>
								未使用
							<#elseif data.status==2>
								已使用
							<#elseif data.status==3>
								已失效
							</#if>
						</td>
						<td>
							<#if data.member??>
								${data.member.name!'暂无'}
								/
								${data.phone!'无'}
							<#else>
								-
							</#if>
						</td>
						<td>
							<#if data.member??>
								${data.member.type}
							<#else>
								-
							</#if>
							
						</td>
						<td>
							<#if data.status!=3>
								<a href="javascript:;" data-value="${data.id}" class="btn-link invalidthis">失效</a>
							</#if>
						</td>
					</tr>
				</#list>
				</#if>
			</tbody>
		</table>
		<#if page.totalElements??>
		<ul class="pagination pull-right pagination-sm">
			<li><a>共 ${page.totalElements} 条数据</a></li>
			<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/couponrule/coupon/${couponRule.id}">
				<@pg.index>
					<@pg.first>
						<li><a href="${pageUrl}">&laquo;</a></li>
					</@pg.first>
					<@pg.prev>
						<li><a href="${pageUrl}">&lsaquo;</a></li>
					</@pg.prev>
					<@pg.pages>
						<#if  currentPageNumber == pageNumber >
							<li class="active"><a href="#">${pageNumber}</a></li>
						<#else>
							<li><a href="${pageUrl}">${pageNumber}</a></li>
						</#if>
					</@pg.pages>
					<@pg.next>
						<li><a href="${pageUrl}">&rsaquo;</a></li>
					</@pg.next>
					<@pg.last>
						<li><a href="${pageUrl}">&raquo;</a></li>
					</@pg.last>
				</@pg.index>
			</@pg.pager>
		</ul>
		</#if>
	</div>
	</div>
	</div>
</div>
</@override>
<@override name="footer">
<script type="text/javascript">
	var thisButton;
	
	function invalidCoupon() {
	    $.post('${ctx}/couponrule/invalidCoupon',{'id':thisButton.attr("data-value")},function(data){
            if(data.success){
                $.scojs_message('操作成功', $.scojs_message.TYPE_OK);
                window.location.reload(true);//强制刷新
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
	    },'json');
	}
	
	$(document).ready(function(){
	
		$(".invalidthis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
            	content: "确认要让该优惠劵失效吗？",
	            action:invalidCoupon
	          });
	          confirm.show();
	    });
	    
		<@shiro.isMainCompany>
			<#if (page.content)?? >
			  	<#list page.content as data>
			  		<#if data.codeKey??>
			  			$("#codeKey_${data.id}").html("${data.codeKey}");
			  		</#if>
			  	</#list>
			</#if>
		</@shiro.isMainCompany>
	
		
		$("#clear_time").click(function(){
			$("#couponCode").val("");
			$("#telephoneNumber").val("");
			$("#SearchForm").submit();
		});

	});
	
</script>
</@override>
<@extends name="../layout.ftl"/>